// pages/answer/answer.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    title:'',
    content:'',
    typelist: [{
      typeId: 1,
      typeName: "全部",
    }, {
      typeId: 2,
      typeName: "精华",
    }, {
      typeId: 3,
      typeName: "热门",
    }, {
      typeId: 4,
      typeName: "最新",
    }],
    display:false,
    default_type:'全部',
    typeId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (wx.showLoading){
      wx.showLoading({
        title: '加载中',
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    if (wx.hideLoading()) {
      wx.hideLoading()
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: 'http://localhost:8080/wxchat/superadmin/findAnswer',
      method:'GET',
      data:{},
      success:function(res){
        var list = res.data.list;
        if (list == null) {
          var toastText = '获取数据失败' + res.data.errMsg;
          wx.showToast({
            title: toastText,
            icon: '',
            duration: 2000
          });
        } else {
          that.setData({
            list: list
          });
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    console.log('隐藏了自己');
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log('卸载了自己');
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  searchAnswer: function (res){
    var that = this;
    wx.request({
      url: 'http://localhost:8080/wxchat/superadmin/findAnswer',
      method: 'GET',
      data: {
         "answerContent":res.detail.value
      },
      success: function (res) {
        var list = res.data.list;
        if (list == null) {
          var toastText = '获取数据失败' + res.data.errMsg;
          wx.showToast({
            title: toastText,
            icon: '',
            duration: 2000
          });
        } else {
          that.setData({
            list: list
          });
        }
      }
    })
  },
  showlist:function(){
    var that = this;
    that.setData({
      display: that.display=!that.display,
    });
  },
  getType:function(e){
    var that = this;
    var typeId = e.target.dataset.id;
    that.setData({
      default_type: e.target.dataset.selected,
      typeId : e.target.dataset.id,
      display: that.display = !that.display
    });
    wx.request({
      url: 'http://localhost:8080/wxchat/superadmin/findAnswerByType',
      data: { "typeId": typeId },
      method: 'GET',
      success: function (res) {
        var list = res.data.list;
        if (list == undefined) {
          var toastText = '获取数据失败' + res.data.errMsg;
          wx.showToast({
            title: toastText,
            icon: '',
            duration: 2000
          });
        } else {
          that.setData({
            list: list
          });
        }
      }
    })
  },
  loseType: function () {
    console.log('失去焦点');
  }
})